package cn.yogehaoren.foxgitstarter;

import cn.yogehaoren.foxgitstarter.common.Constants;
import cn.yogehaoren.foxgitstarter.properties.GitProperties;
import cn.yogehaoren.foxgitstarter.git.FoxGitService;
import cn.yogehaoren.foxgitstarter.runner.GitBookInitRunner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author WangNing
 * date  2021/8/4 23:32
 * @version 1.0
 */
@EnableConfigurationProperties(GitProperties.class)
@Configuration
@ConditionalOnProperty(name = {Constants.ENABLE_GIT})
@ComponentScan({"cn.yogehaoren.foxgitstarter"})
@Slf4j
public class FoxGitAutoConfiguration {

    @Autowired
    FoxGitService foxGitService;

    @Autowired
    GitProperties gitProperties;

    @ConditionalOnProperty(name = {Constants.ENABLE_PULL_ON_START})
    @Bean
    public GitBookInitRunner gitBookInitRunner(){
        return new GitBookInitRunner(foxGitService, gitProperties);
    }

}
